

import java.util.*;
import java.io.*;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

class GestionnaireBillet
{

	public void work ()
	{
		try {
			Billetterie b = null;

			System.out.print("Installing security manager...");
			//if (System.getSecurityManager() == null) {
			System.setSecurityManager(new SecurityManager());
			//}
			System.out.println("done.");

			System.out.print("Getting the registry...");
			Registry registry = LocateRegistry.getRegistry();
			System.out.println("done.");

			System.out.print("Getting the stub...");
			System.out.println("compilé");
			b = (Billetterie)registry.lookup("billetterie");
			System.out.println("done.");

			//mise en place du service
			ASite  sites [] = new ASite[6];
			Circuit circuit = new Circuit();

			for(int i = 0 ; i< 5; i++){
				sites [i] = new Site(b);
				circuit.addSite(sites[i]);
			}	

			sites[5] = new Entree(b);
			circuit.addSite(sites[5]);

			Festivalier fest ;
			for(int i = 0; i < 30 ; i++){
				fest = new Festivalier(sites[2],"Festivalier "+ (i+1) +" " , b);
				if(i%3 == 0){
					fest.setReservationEnLigne(true);
				}
				fest.start();
			}

			for(int i = 0 ; i < 4; i++){
				new Navette(circuit, 4 ,"Navette "+ (i+1)).start();
			}
			//fin mise place

			
			while(true) {
				Thread.sleep(1000);
				int billetsPlus = b.getNbTiketsDispo();
				if (billetsPlus < 10){
					b.ajouterTickets(10 -billetsPlus);
				}
				

			}
			
		} catch (Exception e)
		{
			e.printStackTrace();
		}

	} // work

	public static void main(String args[])
	{
		GestionnaireBillet s = new GestionnaireBillet();
		s.work();
	}


} // Simulateur